﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Text;
using System.Threading.Tasks;

namespace FMS.Formulation.Licensing.Engine
{

    internal class WMIBiosInfo
    {
        private const string WIN32_BIOS = "Win32_BIOS";

        private const string NAME = "Name";

        private const string SERIALNUMBER = "SerialNumber";

        private string biosName = string.Empty;

        private string biosSerialNumber = string.Empty;

        public string Name => biosName;

        public string SerialNumber
        {
            get
            {
                return biosSerialNumber;
            }
            internal set
            {
                biosSerialNumber = value;
            }
        }

        public void Read()
        {
            WqlObjectQuery query = new WqlObjectQuery("SELECT SerialNumber FROM Win32_BIOS");
            ManagementScope scope = new ManagementScope("\\root\\cimv2");
            ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher(scope, query);
            try
            {
                ManagementObjectCollection managementObjectCollection = managementObjectSearcher.Get();
                foreach (ManagementObject item in managementObjectCollection)
                {
                    if (item.Properties["SerialNumber"].Value != null)
                    {
                        biosSerialNumber = item.Properties["SerialNumber"].Value.ToString();
                    }
                }
            }
            catch
            {
            }
        }
    }

}
